import datetime
import mongoengine as db
from app.db import BaseDocument
import arrow


class Follow(BaseDocument):
    """
    # activeName string 必须 活动名称
    # fromURL string 必须 来源链接
    # company string ⾮必须 公司名称
    # contactsName string ⾮必须 客户姓名
    # contactsPhone string ⾮必须 客户电话
    # contactsOccupation string ⾮必须 客户职位
    # industry string ⾮必须 ⾏业
    # product string ⾮必须 产品
    # interestedProduct string ⾮必须 感兴趣的产品
    # customerAccount string ⾮必须 客户账号

    Args:
        BaseDocument ([type]): [description]
    """

    activeName = db.StringField(required=True)
    fromURL = db.StringField(required=True)
    company = db.StringField(max_length=200)
    contactsName = db.StringField(required=True, max_length=20)
    contactsPhone = db.StringField(required=True, max_length=20)
    contactsOccupation = db.StringField(max_length=200)
    industry = db.StringField(max_length=200)
    product = db.StringField(max_length=200)
    interestedProduct = db.StringField(max_length=200)
    customerAccount = db.StringField(max_length=200)
    create_time = db.DateTimeField()

    meta = {
        'collection': 'follows',
        'strict': False
    }

    def save(self, *args, **kwargs):
        if not self.create_time:
            self.create_time = datetime.datetime.utcnow()
        return super(Follow, self).save(*args, **kwargs)
